<?php
/**
 * @version $Id$
 * @package    Jmonoslideshow
 * @author     Matthieu BARBE {@link http://www.ccomca.com}
 * @author     Created on 04-Sep-2009
 */

//-- No direct access

// Check to ensure this file is included in Joomla!
defined('JPATH_BASE') or die;
jimport('joomla.form.formfield');

class JFormFieldSlider extends JFormField
{
	protected $type 		= 'Slider';
	protected $jmonoslideshowParams 	= null;

	protected function getInput() {
	
		$document		= &JFactory::getDocument();
		$option 		= JRequest::getCmd('option');
		
		
		
		
		// Initialize some field attributes.
		$size		= $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';
		$class		= $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';
		$maxLength	= $this->element['maxlength'] ? ' maxlength="'.(int) $this->element['maxlength'].'"' : '';
		$readonly	= ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
		$disabled	= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
		$step		= $this->element['step'] ? ' '.(int) $this->element['step'].'' : '5';
		$divise		= $this->element['divise'] ? ' '.(int) $this->element['divise'].'' : '0';
		$min		= $this->element['min'] ? ' '.(int) $this->element['min'].'' : '0';
		$max		= $this->element['max'] ? ' '.(int) $this->element['max'].'' : '100';
		
		// Initialize JavaScript field attributes.
		$onchange	= $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';
		
		$value 		= htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
		
		if ($divise == 0) 
			{
				$valuejs =  $value;
				$divise = "";
			}
			else
			{
				$valuejs = $value * $divise;
				$divise = "/".$divise;
			}
		
		$script = "
		jQuery(function() {
		
		jQuery('.".$this->id."')[0].slide = null;

		jQuery( '.".$this->id."' ).slider({
			value:".$valuejs.",
			min: $min,
			max: $max,
			step: ".$step.",
			slide: function( event, ui ) {
				jQuery( '#".$this->id."' ).val( ui.value ".$divise." );
			}
		});
		
		});
		";
		$doc = &JFactory::getDocument();
		$doc->addScriptDeclaration($script);

		$html ='<div class="'.$this->id.'" style="float:left; width:300px; margin-top:5px;"></div><input type="text" name="'.$this->name.'" id="'.$this->id.'" value="'.$value.'"'
			   .$class.$size.$disabled.$readonly.$onchange.$maxLength.'/>';		
		
		return $html;

	}
	
	protected function getLabel() {
		echo '<div class="clr"></div>';
		return parent::getLabel();
		echo '<div class="clr"></div>';
	}
	
	
}
?>